home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / unix / textmstr.shr / tm.hqx / Source Code ƒ / P / PUtils_TextMaster.c < prev    next >
Text File  |  1991-05-09  |  9KB  |  245 lines

  1. /*  PUtils_TextMaster                                                     Utilities
  2.  
  3. File name:  PUtils_TextMaster.C  
  4. Function:  Utilities for the Prototyper specific code.
  5. History: 5/9/91 Original by Prototyper 3.0   */
  6.  
  7.  
  8.  
  9. #include "PCommonTextMaster.h"    /* Common */
  10. #include "Common_TextMaster.h"    /* Common */
  11. #include "PUtils_TextMaster.h"    /* This file */
  12.  
  13. /* ======================================================= */
  14.  
  15. /* Routine: TrapAvailable */
  16. /* Purpose: See if trap is available, non-available traps all have a unique address */
  17.  
  18. Boolean TrapAvailable (trapNumber,tType)                             /* See if a trap is available */
  19. short    trapNumber;
  20. short    tType;
  21. {
  22. #define UnimplementedTrapNumber     0xA89F                         /* Unimplemented trap number */
  23. Boolean    theResult;
  24.  
  25. theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));/* Check the two traps */
  26. return(theResult);
  27. }
  28.  
  29.  
  30. /* ======================================================= */
  31.  
  32. /* Routine: GetUserEvent */
  33. /* Purpose: See if any user events are available */
  34.  
  35. void GetUserEvent(UserEventPRec TheUserEvent)
  36. UserEventHRec    NextUserEvent;                                         /* The next user event */
  37.  
  38. TheUserEvent->ID = UserEvent_None;                                    /* Set ID to no events are available */
  39. if (UserEventList != NIL)                                                    /* Get first entry in the list */
  40.     {
  41.     HLock((Handle)UserEventList);                                         /* Lock for safety */
  42.     TheUserEvent->ID = (*UserEventList)->ID;                          /* The event ID */
  43.     TheUserEvent->ID2 = (*UserEventList)->ID2;                       /* The optional ID */
  44.     TheUserEvent->Data1 = (*UserEventList)->Data1;                 /* The optional data */
  45.     TheUserEvent->Data2 = (*UserEventList)->Data2;                 /* The optional data */
  46.     TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  47.     NextUserEvent = (*UserEventList)->Next;                          /* The next list */
  48.  
  49.     DisposHandle((Handle)UserEventList);                                 /* Remove this list item */
  50.     UserEventList = NextUserEvent;                                       /* Make the next item the new first item */
  51.     }
  52. }
  53.  
  54.  
  55. /* ======================================================= */
  56.  
  57. /* Routine: Add_UserEvent */
  58. /* Purpose: Add a user event */
  59.  
  60. void Add_UserEvent( ID,  ID2, Data1, Data2,  theHandle)
  61. short        ID;
  62. short        ID2;
  63. long        Data1;
  64. long        Data2;
  65. Handle    theHandle;
  66. UserEventHRec    NewUserEvent;                                         /* The new user event */
  67. UserEventHRec    theUserEvent;                                          /* The user event */
  68.  
  69. NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  70. if (NewUserEvent != NIL)                                                   /* Only do if we got the new record */
  71.     {
  72.     HLock((Handle)NewUserEvent);                                         /* Lock for safety */
  73.     (*NewUserEvent)->ID = ID;                                             /* The event ID */
  74.     (*NewUserEvent)->ID2 = ID2;                                         /* The optional ID */
  75.     (*NewUserEvent)->Data1 = Data1;                                    /* The optional data */
  76.     (*NewUserEvent)->Data2 = Data2;                                    /* The optional data */
  77.     (*NewUserEvent)->theHandle = theHandle;                          /* The optional handle */
  78.     (*NewUserEvent)->Next = NIL;                                        /* No next item after this one */
  79.  
  80.     if (UserEventList == NIL)                                                /* See if anyone is in the list yet */
  81.         UserEventList = NewUserEvent;                                    /* Make this one the first in the list */
  82.     else                                                                         /* Not the first in the list */
  83.         {
  84.         theUserEvent = UserEventList;                                     /* Get the first one */
  85.         while ((*theUserEvent)->Next != NIL)                             /* Get the next one */
  86.             {
  87.             theUserEvent = (*theUserEvent)->Next;
  88.             }
  89.         (*theUserEvent)->Next = NewUserEvent;                         /* Tack on to the end */
  90.         }
  91.     }
  92. }
  93.  
  94. /* ======================================================= */
  95.  
  96.  
  97. /* This is a routine used to open a user selected file */
  98. /* Return TRUE for opened the file OK, else return FALSE */
  99. Boolean Do_The_Open_File (NumberOfTypes)
  100. short    NumberOfTypes;
  101. {
  102. short    Screen_Width, Screen_Height;                                  /* Size of the current screen */
  103. Point    Where;                                                               /* Used for placing the SF dialog */
  104. Boolean    OpenedOK;                                                        /* Flag to return */
  105.  
  106. Screen_Width = screenBits.bounds.right - screenBits.bounds.left;/* Width of this screen */
  107. Screen_Height = screenBits.bounds.bottom - screenBits.bounds.top;
  108.  
  109. Where.h = (Screen_Width / 2) - (304 / 2);                             /* Place to put this dialog */
  110. Where.v = (Screen_Height / 4) - (104 / 2);
  111. if (Where.v < 60)
  112.     Where.v = 60;
  113. InitCursor();
  114. SFGetFile(Where, "/pNot used", NIL, NumberOfTypes, &typeList, NIL, &Reply);
  115.  
  116. OpenedOK = FALSE;                                                         /* Init to did not open the file */
  117. if (Reply.good)                                                               /* Only do if the user did not cancel */
  118.     {
  119.     /* inputFileName = Reply.fName; */
  120.     ErrorCode = FSOpen(&Reply.fName, Reply.vRefNum, &inputRefNum);/* Open the file */
  121.     if (ErrorCode != 0)                                                       /* See if we did not open it cleanly */
  122.         {
  123.         ErrorCode = FSClose(inputRefNum);                                /* Close it, it may have been left open from before */
  124.         ErrorCode = FSOpen(&Reply.fName, Reply.vRefNum, &inputRefNum);/* Try the open again */
  125.         }
  126.  
  127.     if (ErrorCode != 0)                                                       /* See if we did not open it cleanly */
  128.         {
  129.         ErrorCode = FSClose(inputRefNum);                                /* Close it if we can, safety */
  130.         SysBeep(20);                                                          /* Just beep at the user, caller can do more */
  131.         }
  132.     else
  133.         {
  134.         ErrorCode = SetVol(NIL, inputRefNum);                            /*Set to this volume for later opens */
  135.         OpenedOK = TRUE;                                                     /* Flag that we are open OK */
  136.         }
  137.     }
  138. else
  139.     {
  140.     inputRefNum = 0;                                                         /* We did not open */
  141.     inputFileName[0] = 0;                                                    /* No name for a file */
  142.     }
  143. return(OpenedOK);
  144. }
  145.  
  146.  
  147. /* ======================================================= */
  148.  
  149.  
  150.  
  151. /* This is a routine used to save a user selected file */
  152. /* Return TRUE for opened the file OK, else return FALSE */ 
  153. Boolean Do_The_Save_File (creator,  fileType)
  154. OSType    creator;
  155. OSType    fileType;
  156. {
  157. short Screen_Width, Screen_Height;                                     /* Size of the current screen */
  158. Point Where;                                                                 /* Used for placing the SF dialog */
  159. Boolean OpenedOK;                                                          /* Flag to return */
  160. short theVolRefNum;                                                        /* Volume to save the file in */
  161.  
  162. Screen_Width = screenBits.bounds.right - screenBits.bounds.left;/* Width of this screen */
  163. Screen_Height = screenBits.bounds.bottom - screenBits.bounds.top;
  164.  
  165. Where.h = (Screen_Width / 2) - (304 / 2);                             /* Place to put this dialog */
  166. Where.v = (Screen_Height / 4) - (104 / 2);
  167. if (Where.v < 60) 
  168.     Where.v = 60;
  169. InitCursor();
  170. SFPutFile(Where, "\pSave as : ", "\pUntitled.Text", NIL, &Reply);
  171. /* outputFileName = Reply.fName; */                                   /* Save the output file name */
  172. theVolRefNum = Reply.vRefNum;                                          /* Save the volume refnum */
  173. OpenedOK = FALSE;                                                         /* Init to did not open the file */
  174. if (Reply.good)                                                               /* Only do if the user did not cancel */
  175.     {
  176.     ErrorCode = FSDelete(&Reply.fName, theVolRefNum);             /* Delete an older file */
  177.     ErrorCode = Create(&Reply.fName, theVolRefNum, creator, fileType);/* Create the file */
  178.     ErrorCode = FSOpen(&Reply.fName, theVolRefNum, &outputRefNum);/* Try to open the file */
  179.  
  180.     if (ErrorCode == 0)                                                      /* See if we opened it cleanly */
  181.         {
  182.         ErrorCode = SetFPos(outputRefNum, fsFromStart, 0);         /* Start at file beginning */
  183.         ErrorCode = SetVol(NIL, outputRefNum);                          /* Set for later saves */
  184.         OpenedOK = TRUE;                                                     /* We opened the file OK */
  185.         }
  186.     else
  187.         {
  188.         ErrorCode = FSClose(outputRefNum);                              /* Close it if we can, safety */
  189.         SysBeep(20);                                                          /* Just beep at the user, caller can do more */
  190.         outputRefNum = 0;                                                    /* Make sure the refnum is inited */
  191.         }
  192.     }
  193. return(OpenedOK);
  194. }
  195.  
  196.  
  197. /* ======================================================= */
  198.  
  199.  
  200.  
  201. /* Setup a dialog or alert item */ 
  202. void SetupTheItem( theDialog, ItemID, SizeIt, ShowIt,EnableIt,SetTheMax,thePosition, ExtraData, StringID)
  203. DialogPtr    theDialog;
  204. short        ItemID;
  205. Boolean        SizeIt;
  206. Boolean        ShowIt;
  207. Boolean        EnableIt;
  208. Boolean        SetTheMax;
  209. Rect        *thePosition;
  210. long        ExtraData;
  211. short        StringID;
  212. {
  213. Rect        tempRect;                                                         /* Temporary rectangle */
  214. short    DType;                                                               /* Type of dialog item */
  215. Handle    DItem;                                                              /* Handle to the dialog item */
  216. ControlHandle    CItem;                                                     /* Control handle */
  217.  
  218. GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);            /* Get the item handle and size */
  219. CItem = (ControlHandle)DItem;                                            /* Change to control handle */
  220. if (SizeIt)                                                                     /* Have to resize all CDEF connected controls */
  221.     SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  222. *thePosition = tempRect;                                                  /* Pass back the zone location and size */
  223. if (ExtraData != NIL)                                                         /* See if extra data for a CDEF */
  224.     (*CItem)->contrlData = (Handle)ExtraData;                         /* Send it */
  225. if (StringID != 0)                                                             /* See if a CDEF and needs the title set again*/
  226.     {
  227.     GetIndString(sTemp,StringID,1);                                      /* Get the string */
  228.     SetCTitle(CItem,sTemp);                                                /* Set the string */
  229.     }
  230. if (EnableIt)                                                                   /* See if enable or disable the zone */
  231.     HiliteControl (CItem,0);                                                 /* Enable the zone */
  232. else
  233.     HiliteControl (CItem,255);                                             /* Dim the zone */
  234. if (SetTheMax)
  235.     SetCtlMax(CItem,12345);                                              /* Set the flag to the CDEF */
  236. if (ShowIt)
  237.     ShowControl(CItem);                                                     /* Show it to activate it */
  238.  
  239. }
  240.  
  241. /* ======================================================= */
  242.  
  243.